home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.12 Dec 90 / CleanPict Source / CleanPICT.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-21  |  4.2 KB  |  130 lines  |  [TEXT/MACA]

  1. /*                                            CleanPICT.h                                            */
  2. /*
  3.  * Common definitions for CleanPICT
  4.  */
  5. #define NIL                    ((void *) 0)
  6. #include "OffscreenGrafPort.h"
  7. #define width(r)        ((r).right - (r).left)
  8. #define height(r)        ((r).bottom - (r).top)
  9.  
  10. /*
  11.  * MAGIC converts between the PICT bitmap (which is at
  12.  * 300 dpi) and the screen at 72 dpi.  This should be
  13.  * determined by examining the actual input file so
  14.  * we can handle 72 dpi PICT's too.
  15.  *
  16.  * Note: this is specific to the actual picture -- for
  17.  * some pictures, you don't want this.  If you are
  18.  * trying to clean a picture and nothing seems to be
  19.  * happening, you might try either changing MAGIC to one
  20.  * or try multiplying the threshold by four.
  21.  */
  22. #define MAGIC            4
  23. /*
  24.  * XMAX and YMAX dimension the bit-array that marks
  25.  * the island.  These values should be about twice
  26.  * the size of the largest expected threshold.
  27.  * In any case (XMAX * YMAX) must not exceed 32767.
  28.  * By making XMAX and YMAX powers of two, we can
  29.  * replace multiplies by shifts for a significant
  30.  * speed-up.  If max is too high, the program will
  31.  * run slower (due to the time needed to empty the
  32.  * seen map); if too small, some long thin islands
  33.  * won't be removed.
  34.  */
  35. #define LOG_XMAX     5
  36. #define LOG_YMAX     5
  37. #define    XMAX            (1 << LOG_XMAX)        /* Maximum  pixels    */
  38. #define YMAX            (1 << LOG_YMAX)        /* Maximum  pixels    */
  39. #define    THRESHOLD    8            /* Default threshold                        */
  40.  
  41. typedef unsigned long    Ulong;
  42.  
  43. /*
  44.  * State controls the interaction between the
  45.  * pixel cleaner and the event loop.
  46.  */
  47. enum State {
  48.     Idle = 0,                            /* Must be zero                                    */
  49.     Init,                                    /* Initialize a new cleaning        */
  50.     Working                                /* Cleaning is in progress            */
  51. };
  52.  
  53. /*
  54.  * All the information about a document is stored here.
  55.  * Note that, when the toolbox selects a window, we can
  56.  * immediately recover the document.  This lets us work
  57.  * on multiple documents, which is probably useless
  58.  * even though it's easy to do.
  59.  */
  60. typedef struct {
  61.     WindowRecord    window;                    /* Watch process here        */
  62.     GrafPtr                pictPort;                /* The PICT itself            */
  63.     Rect                    pictSize;                /* The picture's bounds    */
  64.     enum State        state;                    /* What's up, DOC?            */
  65.     short                    threshold;            /* Island threshold            */
  66.     Boolean                dirty;                    /* TRUE if need write        */
  67.     Str255                fileName;                /* PICT's file name            */
  68.     /*
  69.      * The count variable is incremented whenever an island
  70.      * point is seen.  If it exceeds threshold, this is
  71.      * not an erasable island.
  72.      */
  73.     short                    count;
  74.     /*
  75.      * The center variable defines the point currently
  76.      * being examined as a potential island.  This variable
  77.      * is in the DOC.pictPort coordinate space.
  78.      */
  79.     Point                center;
  80.     /*
  81.      * These two values define the bottom of the PICT:
  82.      * we don't look at the last row or column.  These
  83.      * probably should be Ulong's
  84.      */
  85.     short                    bottom;
  86.     short                    right;
  87.     /*
  88.      * The island variable defines the "color" we're looking
  89.      * for: this needs some work to handle color PICT's.
  90.      */
  91.     Boolean                island;
  92.     /*
  93.      * The updateRect tracks the pixels that need to be
  94.      * changed on screen.  updateCount is used to determine
  95.      * when to force an update.
  96.      */
  97.     RgnHandle            thisUpdateRgn;    /* The current island        */
  98.     RgnHandle            updateRgn;        /* This needs updating        */
  99.     short                    updateCount;    /* When this overflows        */
  100.     /*
  101.      * Here are some statistics for user-friendlyness.
  102.      */
  103.     Ulong                    examined;            /* Points closely watched    */
  104.     Ulong                    found;                /* Islands erased                    */
  105.     Ulong                    start;                /* When cleaning started    */
  106.     Ulong                    elapsed;            /* Elapsed seconds                */
  107.     Ulong                    elapsed_shown;    /* On about window            */
  108. } DocumentRecord, *DocumentPtr;
  109.  
  110. /*
  111.  * The current window is always stored in a local
  112.  * WindowPtr variable named "window."  If it's ours,
  113.  * we can access the document by casting window to
  114.  * DocumentPtr and de-referencing it.
  115.  */
  116. #define DOC            (*((DocumentPtr) window))
  117.  
  118. void                        clean_picture(WindowPtr, Boolean);
  119. OSErr                        read_picture(WindowPtr, int);
  120. void                        update_picture(WindowPtr);
  121. void                        write_picture(WindowPtr, int);
  122. void                        make_about_window(WindowPtr);
  123.  
  124. #define pstrcpy(out, in)                                                        \
  125.     BlockMove((in), (out), ((unsigned char *)(in))[0] + 1)
  126. void                        pstrcat(void *, void *);
  127. #define WATCH_CURSOR    SetCursor(*GetCursor(watchCursor))
  128. #define ARROW_CURSOR    SetCursor(&arrow)
  129.  
  130.